﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using MapEntities;
using Microsoft.SharePoint.WebPartPages;

namespace KDPWebPart.Layouts.KDPWebPart
{
    public partial class EditMapData : LayoutsPageBase
    {
        protected void btnSave_click(object sender, EventArgs e)
        {
            MapDataRequest req = ctlMapDataEditor.EndEdit();
            SharepointdMapDataProvider provider = new SharepointdMapDataProvider();
            SPLimitedWebPartManager mng ;
            MapWebPart.KDPMapWebPart kpart = (MapWebPart.KDPMapWebPart)provider.GetWebPart(new Guid(Request["id"]), Request["url"], out mng );
            kpart.SaveMapData(req);
            mng.SaveChanges(kpart);
            Page.ClientScript.RegisterStartupScript(typeof(MapDataRequest), "close", "<script type='text/javascript'>self.close();if (window.opener && !window.opener.closed) {window.opener.location=window.opener.location;} </script>");

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && !string.IsNullOrEmpty(Request["id"]) && !string.IsNullOrEmpty(Request["url"]))
            {
                SharepointdMapDataProvider provider = new SharepointdMapDataProvider();
                MapDataRequest req = provider.GetMapData(new Guid(Request["id"]), Request["url"]);                
                ctlMapDataEditor.Edit(req);
                //ctlSave.Attributes.Add("onClick", string.Format("javascript:self.close()"));
                //ctlSave.OnClientClick = string.Format("__doPostBack('ctlSave', 'Click'); javascript:self.close();return true;");
         

            }
        }
    }
}
